function Salary_Code() {
	var buffer = new StringBuffer();
	buffer.append('<div id="find" class="finds"><div class="searchinput ui-border-radius"><input id="keyword" class="bordersolid" type="text" value="" onblur="Show_Search()" onkeyup="Salary_Search();"/></div><div id="searchicon" class="searchicon"><img src="img/jing.jpg"/></div><div id="searchicons" class="searchicons"><img src="img/jings.jpg"/></div><div class="screen"><button id="screen" class="ui-border-radius">筛选</button></div></div>');
	buffer.append('<div class="horizen border-bottom"></div>');
	return buffer.toString();
};
function Salary_Data(data) {
	var buffer = new StringBuffer();
	$(data).each(function(i,info){
		buffer.append('<div class="matelist border-bottom" id="'+info.ID+'"><div class="matename"><div class="realname">'+info.RealName+'</div><div class="birthplace">'+info.BirthPlace+'</div></div><div class="mateinfo"><div class="sex">'+info.Sex+'&nbsp;('+DateDiff("Y", info.Birthday, now+'')+'岁)</div><div class="joindate bsalary">薪资：<font>'+info.BSalary.toFixed(2)+'</font></div></div></div>');
	});
	return buffer.toString();
};
function Init_Salary_Code()
{
	get("find").addEventListener("tap",function(){
		$("#searchicon").hide();
	    $("#searchicons").show();
	    $("#keyword").attr("placeholder","姓名、用户名、电话");
		if($("keyword").val()!="")
		{
			//WorkMate_Search();
		}
	});
	get("screen").addEventListener("tap",function(){
		OpenScreen(User_Search_Code(),function(){
			Init_User_Search();
		},Salary_Search);
		stopEvent();
	});
};
function Salary_Search(){
	pageindex=1;
	$("#divmsg1").attr("pageindex","0");
	Receive_Salary(1);
};
function Receive_Salary(pageindex)
{
	var isenable=RUndefined($("input[name='state_search']:checked").val());
	var departid=RUndefined($("#depart_search").val());
	var data = {};
			data.act = "Find_User";
			data.userid=userid;
			data.comid=comid;
			data.pageindex=pageindex;
			data.source=source;
			data.pagesize=PAGE_SIZE20;
			data.keyword = $("#keyword").val();
			data.timer = RUndefined($("#begindate_search").val()) + "～" + RUndefined($("#enddate_search").val());
		    data.isenable = isenable==""?"true":isenable;
    		data.departid = departid==""?"0":departid;
    		data.sign=GetSign(data.act);
			
			mui.getJSON(admin_domain, data, function(json) {
				if(json.data.user.length>0)
				{
					if(pageindex==1)
					{
						$("#contentlist1").html(Salary_Data(json.data.user));
					}else{
						$("#contentlist1").append(Salary_Data(json.data.user));
					}
					setTimeout(function(){
						Init_Salary();
						myScroll1.refresh();
					},500); //需要延迟500毫秒加载，否则当数量少时不能下拉
					if(json.data.user.length!=data.pagesize)
					{
						$("#loading1").html("");
					}else{
						$("#loading1").html('<img src="img/loading.gif"/>');
					}
				}else
				{
					
					if(pageindex==1)
					{
						$("#contentlist1").html("");
						$("#loading1").html("主人，没有找到您需要的数据"); 
					}
					else
					{
						$("#loading1").html("没有更多了");
					}
				}
				
         		pageindex = parseInt($("#divmsg1").attr("pageindex"))+1;
         		$("#divmsg1").attr("pageindex",pageindex);
			});
};
function Init_Salary()
{
	mui("#contentlist1").off("tap",".matelist");
	mui("#contentlist1").on("tap",".matelist",function(){
		obj=$(this);
		OpenWindow(2,obj.find(".realname").html()+"薪资调整记录","调薪",function(){
			OpenWindow(3,"调薪","保存",function(){
				Save_Salary();
			});
			$("#contentlist3").html(SalaryAdd_Code(0,obj.find(".realname").html(),obj.find(".bsalary font").html(),0,""));
			Init_SalaryAdd();
		});
		SalaryDetail_Data();
	});
	
};
function SalaryDetail_Data(){
	
	var data = {};
		data.act = "Find_Salary";
		data.uid=obj.attr("id");
		data.source=source;
		data.userid=userid;
		data.comid=comid;
		data.sign=GetSign(data.act);
		
		mui.getJSON(index_domain, data, function (json) {
			var str="";
		    if (json.state) {
		    	if(json.data.list.length>0)
		    	{
			    	$.each(json.data.list,function(i,info){
			    		str+='<div class="matelist border-bottom" id="'+info.ID+'" bak="'+info.Bak+'"><div class="matename"><div class="realname">'+obj.find(".realname").html()+'</div><div class="birthplace increasesalary">'+(info.IncreaseSalary>0?"涨薪":"降薪")+'：'+(info.IncreaseSalary>0?'<font class="greens">'+info.IncreaseSalary.toFixed(2)+'</font>':'<font class="reds">'+Math.abs(info.IncreaseSalary).toFixed(2)+'</font>')+'</div></div><div class="mateinfo"><div class="sex">调薪日期：'+info.CreateDate.ToDate()+'</div><div class="joindate">当前薪资：'+info.NowSalary.toFixed(2)+'</div></div></div>';
			    	});
			    	$("#contentlist2").html(str);
		    	}else
		    	{
		    		$("#contentlist2").html('<div id="loading2" class="loading">主人，没有找到相关薪资记录</div>');
		    	}
		    }
		    if($("#contentlist2 .matelist").length>0){
			    $("#contentlist2 .matelist:last")[0].addEventListener("tap",function(){
			    	OpenWindow(3,"调薪","保存",function(){
						Save_Salary();
					});
					
					$("#contentlist3").html(SalaryAdd_Code($(this).attr("id"),obj.find(".realname").html(),obj.find(".bsalary font").html(),$(this).find(".increasesalary font").html(),$(this).attr("bak")));
					Init_SalaryAdd();
			    });
			    $("#contentlist2 .matelist:not(:last)").each(function(){
			    	this.addEventListener("tap",function(){
			    		plus.nativeUI.toast("仅最后一条调薪可以编辑");
			    	});
			    });
			    
			    	
		    }
		});
		
};
function SalaryAdd_Code(id,realname,bsalary,increasesalary,bak){
	var buffer = new StringBuffer();
	var increase=increasesalary;
	if(id==0)
	{
		increase="";
	}
	buffer.append('<div id="salaryid" val="'+id+'" class="crmsheet border-bottom"><div class="ctitle"><div class="cname">员工姓名</div></div><div class="ctext"><input type="text" readonly="readonly" value="'+realname+'" /></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">原始薪资</div></div><div class="ctext"><input id="txt_originalsalary" type="text" readonly="readonly" value="'+(bsalary- parseFloat(increasesalary)).toFixed(2)+'" /></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">涨薪/降薪</div><div class="require"></div></div><div class="ctext"><div class="sex"><input id="boy" name="txt_type" type="radio" style="width:16px;" checked="checked" value="+" onclick="Change_Salary()"/><label for="boy">涨薪</label></div><div class="sex"><input id="girls" name="txt_type" type="radio" style="width:16px;" value="-" onclick="Change_Salary()"/><label for="girls">降薪</label></div></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">调整金额</div><div class="require">*</div></div><div class="ctext"><input id="txt_increasesalary" type="tel" placeholder="填写涨薪或降薪金额" value="'+increase+'" onkeyup="Change_Salary();"/></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">最新薪资</div></div><div class="ctext"><input id="txt_nowsalary" type="text" readonly="readonly" value="'+bsalary+'"/></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">备注</div></div><div class="ctext"><textarea id="txt_bak" placeholder="调薪备注"  style="height:120px;">'+bak+'</textarea></div><div class="carrow"></div></div>');
	if(id!=0){
	buffer.append('<div id="deletesheet" class="deletesheet" style="margin-top:50px;"><div class="name" style="width:100%; text-align:center;">删除该调薪</div></div>');
	}
	return buffer.toString();
};
function Change_Salary(){
	if(!isNaN($("#txt_increasesalary").val()))
	{
		if($("#txt_increasesalary").val()==""){
			$("#txt_nowsalary").val($("#txt_originalsalary").val());
		}else{
		    $("#txt_nowsalary").val((parseFloat($("#txt_originalsalary").val())+parseFloat($("input[name='txt_type']:checked").val()+$("#txt_increasesalary").val())).toFixed(2));
		}
	}
};

function Init_SalaryAdd(){	
	
};


function Save_Salary() {
        var data = {};
        var txt_originalsalary = $("#txt_originalsalary");
        var txt_increasesalary = $("#txt_increasesalary");
        var txt_nowsalary = $("#txt_nowsalary");
        data.id = $("#salaryid").attr("val");
        if(txt_increasesalary.val().Trim()=="")
        {
        	plus.nativeUI.toast("请输入调整金额");
        	return false;
        }
        if(parseInt(txt_increasesalary.val())<=0)
        {
        	plus.nativeUI.toast("调整金额必须大于0");
        	return false;
        }
        if(isNaN(txt_increasesalary.val()))
        {
        	plus.nativeUI.toast("调整金额必须为数字");
        	return false;
        }
		data.act = "Save_Salary";
		data.uid=obj.attr("id");
		data.originalsalary = txt_originalsalary.val();
        data.increasesalary = $("input[name='txt_type']:checked").val() + txt_increasesalary.val();
        data.nowsalary = txt_nowsalary.val();
        data.bak=$("#txt_bak").val();
        data.userid=userid;
		data.comid=comid;
        data.source = source;
        data.version = version;
        data.sign=GetSign(data.act);
        plus.nativeUI.showWaiting( "正在执行..." );
	    CloseWaiting(10000);
        mui.getJSON(index_domain, data, function (json) {
        	plus.nativeUI.closeWaiting();
        	plus.nativeUI.toast(json.msg); 
            if (json.state) {
                CloseWindow(); 
                obj.find(".bsalary font").html(data.nowsalary);
                SalaryDetail_Data();
            }
        });
};
